<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
	<script src="lib/react.development.js"></script>
	<script src="lib/react-dom.development.js"></script>
	<script src="lib/babel.min.js"></script>
</head>
<body>
<div id="root">

</div>
</body>
<script type="text/babel">
	const root = ReactDOM.createRoot(document.querySelector("#root"));
	// 1- 与普通元素结合使用，可以获取到真实的DOM
	// 2- 与类组件结合使用，可以获取类组件实例（实现组件间的通讯）
	class Child extends React.Component{
		state = {
			num:100
		}
		render(){
			return (
				<h3>Child->{this.state.num}</h3>
			)
		}
	}
	class App extends React.Component{
		render(){
			return (
				<div>
					<p ref={el=>{
						// 1-挂载会执行
						// 2-接收的参数即是p元素对象
						console.log("p->ref")
						// console.log(el)
						this.refP = el;
					}}>我现在正在学习React</p>
					<Child ref={el=>this.childRef = el}/>
					<button onClick={()=>{
						// console.log(document.querySelector("p"));
						console.log(this.refP === document.querySelector("p"));
						this.childRef.setState({
							num:999
						})
					}}>点我</button>
				</div>
			)
		}
	}
	root.render(<App/>)
</script>
</html>